package com.ddfeiyu.agreement;


import com.ddfeiyu.agreement.log.LogRequest;
import com.ddfeiyu.agreement.log.LogResponse;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class Packet {

    private final static Map<Byte, Class<? extends Packet>> packetType = new ConcurrentHashMap<>();

    static {
        packetType.put(Command.LogRequest, LogRequest.class);
        packetType.put(Command.LogResponse, LogResponse.class);

        packetType.put(Command.ReconnectRequest, ReconnectRequest.class);

    }

    public static Class<? extends Packet> get(Byte command) {
        return packetType.get(command);
    }

    /**
     * 获取协议指令
     *
     * @return 返回指令值
     */
    public abstract Byte getCommand();
}
